from cgitb import text
import django.utils.timezone as timezone
from django.db import models
 
class User(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=30, unique=True)
    password = models.CharField(max_length=50)
    introduction = models.CharField(max_length=300)
    avatar = models.CharField(max_length = 100)
    email = models.EmailField(max_length=70, null=True, blank=True) # one type of CharField
    # state: valid=0, not_varified=1, test=2, deleted=3,
    state = models.IntegerField(default=0)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

class Post(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=50)
    abstract = models.CharField(max_length=200)
    content = models.TextField()
    # type: normal=0, draft=1, deleted=2,
    type = models.IntegerField(default=0)
    # style: images:
    style = models.IntegerField(default=0)
    location = models.CharField(max_length=100)
    author = models.ForeignKey(User, related_name='user_post', on_delete=models.CASCADE)
    author_name = models.CharField(max_length=30)
    like_num = models.IntegerField(default=0)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

class Comment(models.Model):
    id = models.AutoField(primary_key=True)
    content = models.TextField()
    post = models.ForeignKey(Post, related_name='post_comment', on_delete=models.CASCADE)
    author = models.ForeignKey(User, related_name='user_comment', on_delete=models.CASCADE)

class Notice(models.Model):
    id = models.AutoField(primary_key=True)
    time = models.CharField(max_length=100)
    content = models.CharField(max_length=200)
    receiver = models.ForeignKey(User, related_name='user_notice', on_delete=models.CASCADE)
    read = models.BooleanField(default=False)

class Follower(models.Model):
    id = models.AutoField(primary_key=True)
    star = models.ForeignKey(User, related_name='user_star', on_delete=models.CASCADE)
    fan = models.ForeignKey(User, related_name='user_fan', on_delete=models.CASCADE)

class Blocker(models.Model):
    id = models.AutoField(primary_key=True)
    host = models.ForeignKey(User, related_name='user_host', on_delete=models.CASCADE)
    enemy = models.ForeignKey(User, related_name='user_enemy', on_delete=models.CASCADE)

class Liker(models.Model):
    id = models.AutoField(primary_key=True)
    state = models.BooleanField(default=True) # 默认值 True, 表示关注。取关时置为 False
    post = models.ForeignKey(Post, related_name='post_liker', on_delete=models.CASCADE)
    reader = models.ForeignKey(User, related_name='user_liker', on_delete=models.CASCADE)

class PictureRecorder(models.Model):
    id = models.AutoField(primary_key=True)
    image = models.ImageField(upload_to="images")

class VideoRecorder(models.Model):
    id = models.AutoField(primary_key=True)
    video = models.FileField(upload_to="videos")

class AudioRecorder(models.Model):
    id = models.AutoField(primary_key=True)
    audio = models.FileField(upload_to="audios")